Hello and welcome to this lecture in this part two of the barns and the ball lectures we will be implementing.
Coalition detection the coalition detection will check if the ball is touchin or colliding with the
wars on the campus.
There are four walls of the campus.
You've got the top the bottom left and the right.
So we'll implement coalition detection to spot or detect if there's any coalition between any of the
walls.
If there is any will will create calculations so that the ball will change the direction of this movement.
We are going to create a variable called ball radius.
This variable will hold the radius of the drawn circle that will be used to perform the cuk relations.
OK so let's create the variable create its other top here called fireable.
We are very low call ball
radius.
Now give it a value
of 10.
Now that we've created a variable called ball radius is less of date are drawn ball function.
So where we've got the rate is here we removed this value and replace that will borate Yes
we can send them.
All right.
This is a value we need to remove the actual radius and then to get too many commas there.
So that's the X Y variable and this is the borate of variable.
And then there's this the Ark where the ark starts and this is where they are.
NS There are four walls for the ball to bounce off the Cambers with the top the bottom the left and
the right.
Okay let's determine the how we cut callate the coalition point of the Bosso conference.
We got to do this using if statements okay we're going to place the statement just below the drop ball
function.
So what we are going to say is we're going to start with the left and the right wars.
So we'll see if
the x variable bloss Details variable
is greater.
So if the x variable Plus the Dick's variable is greater than the come fast
with.
Minus the borate Yes.
So it explores the experienceable is greater than the covers weight minus the ball radius all this symbol
of pipe Emens or all x bloss the x variable is less than the ball radius.
Okay.
So this is the statement here.
So we're saying if this x plus the x is greater than the come of us with mine or the boy radios or if
exploded the AIDS variable is less than the borate does.
This is what should happen.
We put calibrate since it should what should happen is that is either this condition is true.
The first condition is true or it's a second condition is true.
This is what we want to happen.
We want the value of x to be equal to.
Two equals two minus the decks.
So this is what will happen if the first condition or the second condition is true in if it meant the
value of Diddy's x variable would be it to minus the x variable.
Thus we relate to the left and the right was of the compass.
So for the top the bottom will be equal use the same code and being lasic one going to do just copy
this if statement has changed the value.
Copy here.
Okay and I'll just change the values so it would be Y.
If y plots the y
y plausible y canvas dot right
okay.
Minus the ball radius or wine laws the Y is less than the boy radius.
If that condition is true indeed y will be lost to a minus D Y.
All right so this is State me too.
Is it menhir I use to implement a simple coalition detection that will make the board change direction.
If any completion is detected.
So the first.
What if statement here refers to the left and the right was of the compass.
If the X blows the D X variables is greater than the compass with minors bore radius.
No Remember I've declared the value of football radio so we're saying that the x variable Plus the variable
is greater than become vets with minus the ball radios.
Or if the x variable plots the defence variable is less than the ball radius then this condition between
this curly braces will happen.
That means the value of the X will be equal to or minus dicks in the second if statement.
This will refer to the top and the bottom was on the Cambers.
If the Y variable plods the D Y variable is greater than the converse height minus the ball radials
or if y plus D Y variable is less than the ball radius.
Then the condition between the curly braces will happen.
That means the value of the D Y variable will be equal force to minus the Y.
So this is just a simple coalition detection implementation using the if statements.
See when the distance between the centre of the ball and the edge of the wall is exactly the same as
the radius of the ball.
It will change the direction of movement so subtracting the radials from one edge with an add in it
on to dolar give the impression that some coalition has been detected and then the ball bounces off
the wall.
So save the code.
Okay then check are hastier mount and see what the code looks like.
Go run lunch in Chrome.
We should have a proper coalition detection you see that.
So the ball is now within the compass.
Cause there's a collision detection in place it says bouncing off the walls of the compass so that's
it for this project.
Thank you so much for your time in watching.
If you have any questions whatsoever please do not hesitate to contact me.
TRAMP practice and change some of the values of what we have learned and just play around to familiarize
yourself with the way things work.
Don't be scared to break anything you can always make copies of your original code and just try and
break it.
Try new things and improve your skills.
Thank you so much.
And by for.